package com.java.jvm.memory;
/**
 * 逃逸分析参数：-XX:+DoEscapeAnalysis
 * -Xmx128m -Xms128m -XX:-DoEscapeAnalysis -XX:+PrintGC
 */
public class EscapeAnalysisTests {
    public static void main(String args[]) throws InterruptedException {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++) {
            //alloc1();
            //alloc2();
              data=alloc3();
        }
        long end = System.currentTimeMillis();
        System.out.println("花费的时间为： " + (end - start) + " ms");
    }

    static void alloc1(){
        byte[] data=new byte[1];//未逃逸的小对象可以分配在栈上
    }
    static byte[] data;
    static void alloc2(){
        data=new byte[1];//对象发生逃逸
    }
    static byte[] alloc3(){
      return new byte[1];//对象可能会发生逃逸
    }

}
